import json

def load_json(_path):
    with open(_path, 'r', encoding='utf-8') as _json_file:
        _json_content = json.load(_json_file)
        _json_file.close()
    return _json_content

def dump_json(_json_content, _path):
    with open(_path, 'w') as _json_file:  # 生成json文件
        json.dump(_json_content, _json_file, indent=4, separators=(',', ': '))
        _json_file.close()

input_src = r'E:\ind-veision\project\learn\commontools\images_divide\val.json'
out_src = r'E:\ind-veision\project\learn\commontools\images_divide\val_1.json'
json_content = load_json(input_src)

for enum_anno_dict in range(len(json_content['annotations'])-1, -1, -1):
    json_content['annotations'][enum_anno_dict]['area'] = json_content['annotations'][enum_anno_dict]['bbox'][2] *\
                                                          json_content['annotations'][enum_anno_dict]['bbox'][3]
dump_json(json_content, out_src)
